package com.xuecheng.content.controller;

import com.xuecheng.commons.model.dto.TeachplanDto;
import com.xuecheng.commons.model.vo.ResponseResult;
import com.xuecheng.commons.model.vo.TeachplanVo;
import com.xuecheng.commons.utils.BeanHelper;
import com.xuecheng.content.domain.Teachplan;
import org.springframework.web.bind.annotation.*;
import com.xuecheng.content.service.TeachplanService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * <p>
 * 课程计划前端控制器
 * </p>
 *
 * @author itheima
 */
@Slf4j
@RestController
public class TeachplanController {

    @Autowired
    private TeachplanService  teachplanService;


    /*// feign查询课程计划
    @GetMapping("/teachplan/garde/{courseId}")
    public ResponseResult treeNodes3(@PathVariable("courseId") Long courseId){
        return teachplanService.treeNodes3(courseId);
    }*/

    // 查询课程计划
    @GetMapping("/teachplan/{courseId}/tree-nodes")
    public ResponseResult treeNodes(@PathVariable("courseId") Long courseId){
       // return teachplanService.treeNodes(courseId);
        return teachplanService.treeNodes2(courseId);
    }


    // 保存或修改课程计划
    @PostMapping("/teachplan")
    public ResponseResult saveOrUpdateTeachplan(@RequestBody TeachplanDto dto){
        return teachplanService.saveOrUpdateTeachplan(dto);
    }


    // 删除课程计划
    @DeleteMapping("/teachplan/{id}")
    public ResponseResult deleteTeachplan(@PathVariable("id") Long id){
        return teachplanService.deleteTeachplan(id);
    }

    /*
        根据id查询课程计划（大纲）
            请求：
                地址：/teachplan/{teachplanId}
                方式：GET
            返回：
                teachplanVo
     */
    @GetMapping("/teachplan/{teachplanId}")
    public ResponseResult findTeachplanById(@PathVariable("teachplanId")Long teachplanId){
        // 1.查询service
        Teachplan teachplan = teachplanService.getById(teachplanId);
        // 2.封装vo
        TeachplanVo vo = BeanHelper.copyProperties(teachplan, TeachplanVo.class);
        // 3.返回
        return ResponseResult.okResult(vo);
    }
}
